//消息窗口详情 显示/删除
function controllerMsg(id,flag) {
	controllerWaiting(true);
	$(".bg").fadeIn(100);
	//记录ID
	$("#msgA").attr("title",id);
	if(flag) {
		$("#configInfo").fadeIn(400);
		$.ajax({
			type:"post",
			dataType:"text",
			data:{"id":id},
			url:getContextPath()+"/notice/msgInfo",
			success:function(msg) {
				var msgs=msg.split("#$");
				$("#titleHidden").val(msgs[0]);
				$("#msgTitle").val(msgs[1]);
				$("#msgContent").text(msgs[2]);
			}
		});
	}
	else {
		if(confirm("确定删除吗?")) {
			$.ajax({
				type:"post",
				dataType:"text",
				data:{"id":id},
				url:getContextPath()+"/notice/delMsg",
				success:function(msg) {
					if(msg==1)
						window.location=getContextPath()+"/notice/msg/1";
					else
						alert("服务器繁忙 请稍后再试");
				}
			});
		}
	}
	$(".bg").fadeOut(100);
	controllerWaiting(false);
}

//修改 或 新增 消息
function updateMsg() {
	$(".bg").fadeIn(100);
	controllerWaiting(true);
	var title=$("#msgTitle").val();
	var content=$("#msgContent").val();
	var id=$("#msgA").attr("title");
	$.ajax({
		type:"post",
		dataType:"text",
		data:{"id":id,"msgTitle":title,"msgContent":content},
		url:getContextPath()+"/notice/updateMsg",
		success:function(msg) {
			if(msg==1)
				window.location=getContextPath()+"/notice/msg/1";
			else
				alert("服务器繁忙 请稍后再试");
		}
	});
	controllerWaiting(false);
	$(".bg").fadeOut(100);
}

//显示新增消息DIV
function showAddMsgDiv() {
	$(".bg").fadeIn(100);
	$("#configAdd").fadeIn(400);
}

//添加消息
function addMsgDiv() {
	$(".bg").fadeIn(100);
	$("#configAdd").fadeIn(400);
	controllerWaiting(true);
	var title=$("#msgTitleAdd").val();
	var content=$("#msgContentAdd").val();
	$.ajax({
		type:"post",
		dataType:"text",
		data:{"msgTitle":title,"msgContent":content},
		url:getContextPath()+"/notice/newMsg",
		success:function(msg) {
			if(msg==1)
				window.location=getContextPath()+"/notice/msg/1";
			else
				alert("服务器繁忙 请稍后再试");
		}
	});
	$(".bg").fadeOut(100);
	controllerWaiting(false);
}

//关闭消息添加窗口
function closeConfigAddDiv() {
	$(".bg").fadeOut(100);
	$("#configAdd").fadeOut(300);
}

//公告窗口详情 显示/删除
function controllerPolicy(id,flag) {
	$(".bg").fadeIn(100);
	controllerWaiting(true);
	if(flag) {
		$("#configInfo").fadeIn(400);
		$.ajax({
			type:"post",
			dataType:"text",
			data:{"id":id},
			url:getContextPath()+"/notice/policyInfo",
			success:function(msg) {
				var msgs=msg.split("#$");
				$("#titleHidden").val(msgs[0]);
				$("#msgTitle").val(msgs[1]);
				$("#msgContent").text(msgs[2]);
			}
		});
	}
	else {
		if(confirm("确定删除吗?")) {
			$.ajax({
				type:"post",
				dataType:"text",
				data:{"id":id},
				url:getContextPath()+"/notice/delPolicy",
				success:function(msg) {
					if(msg==1)
						window.location=getContextPath()+"/notice/policy/1";
					else
						alert("服务器繁忙 请稍后再试");
				}
			});
		}
	}
	$(".bg").fadeOut(100);
	controllerWaiting(false);
}

function downloadURL() {
	window.location=getContextPath()+"/notice/download?url="+encodeURI(encodeURI($("#urlHidden").val()));
}

function downloadURLByParam(url) {
	window.location=getContextPath()+"/notice/download?url="+encodeURI(encodeURI(url));
}
//分页
function msgPageController(value) {
	var pageCount=$("#pageCount").val();
	var msgTitle=$("#dname").val();
	var timeUp=$("#timeUp").val();
	var timeDown=$("#timeDown").val();
	if(value<1)
		value=1;
	if(value>pageCount)
		value=pageCount;
	if(value=="jump")
		value=$("#pageJump").val();
	window.location=getContextPath()+"/notice/searchMsg/"+value+"?msgTitle="+encodeURI(encodeURI(msgTitle))+"&timeUp="+timeUp+"&timeDown="+timeDown;;
}

//分页
function policyPageController(value) {
	var pageCount=$("#pageCount").val();
	var msgTitle=$("#dname").val();
	var timeUp=$("#timeUp").val();
	var timeDown=$("#timeDown").val();
	if(value<1)
		value=1;
	if(value>pageCount)
		value=pageCount;
	if(value=="jump")
		value=$("#pageJump").val();
	window.location=getContextPath()+"/notice/searchPolicy/"+value+"?msgTitle="+encodeURI(encodeURI(msgTitle))+"&timeUp="+timeUp+"&timeDown="+timeDown;
}